<?php
    $item_menu[0] = 6; 
    $item_menu[1] = 2;  
    $title = 'Prestadores';
	
	include('header.php');

	if (!isset($_SESSION["admin"])) {redirect("login.php");	exit(); }


	$accion = request('accion','');

	if($accion=='importar'){
		$producto_id = request('producto_id',0);
		$sql = "select * from productos where id='$producto_id'";
		$rs = $db->SelectLimit($sql,1);
		$data = $rs->FetchRow();
		
		$data['nombre'] = $data['titulo'];
		$data['email1'] = $data['email'];
		$data['persona1'] = $data['persona_contacto'];
		$data['producto_id'] = $producto_id;
		

	} elseif($accion=='guardar'){
		$data = $_POST['data'];
		$ok = $db->Replace('prestadores', $data,'id', $autoquote = true); 
		
		$sql = "select id from prestadores where nombre='{$data['nombre']}'";
		$rs  = $db->SelectLimit($sql,1);
		$x = $rs->FetchRow();
		
		
		redirect('reservas-prestadores_editar.php?id='.$x['id']);
		die();

	} else {
		$sql = "select * from prestadores where id='$id'";
		$rs  = $db->SelectLimit($sql,1);
		$data = $rs->FetchRow();
	}
	
	
	
	
?>
	<h2>Nuevo Prestador de Servicios</h2>
	<?php if($id==0){?>
		<link rel="stylesheet" href="<?php echo URL;?>/css/ui.css" />
		<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
	
		<form class="form-search" method='post' action='<?php echo URL;?>/admin/reservas-prestadores_nuevo.php'>
			<table><tr>
				<td><legend>Importar de Alojamientos:</legend></td>
				<td><input type="text" id="prestador" class="input-xxlarge" name='prestador'></td>
				<td>
					<input type="hidden" id="producto_id" name='producto_id'>
					<input type="hidden" id="accion" name='accion' value='importar'>
					<button type="submit" name='buscar' class="btn">Importar</button>
				</td>
			</tr></table>
		</form>
		<script type="text/javascript">
			$(document).ready(function() {
				// Autocomplete
				$( "#prestador" ).autocomplete({
						source: "<?php echo URL;?>/ajax/autocomplete_alojamientos.php",
						minLength: 2,
						select: function( event, ui ) {
							$( "#producto_id" ).val( ui.item.id );
						}
				});
			});
		</script> 
	<?php } ?>


		<form method='post' action='<?php echo URL;?>/admin/reservas-prestadores_nuevo.php'>
		<div class="control-group">
			<label class="control-label" for="inputNombre">Nombre (*):</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[nombre]' id="nombre" required value='<?php echo $data['nombre'];?>'>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="inputNombre">Direccion (*):</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[direccion]' id="direccion"  value='<?php echo $data['direccion'];?>'>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label" for="inputNombre">Web:</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[web]' id="web"  value='<?php echo $data['web'];?>'>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label" for="inputNombre">Contacto 1:</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[persona1]' id="persona1"  value='<?php echo $data['persona1'];?>'>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label" for="inputEmail">Email 1:</label>
			<div class="controls">
				<input type="email" class='input-xxlarge' name='data[email1]' id="inputEmail1" value='<?php echo $data['email1'];?>'>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label" for="inputApellido">Telefono 1:</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[telefono1]' id="telefono1" value='<?php echo $data['telefono1'];?>'>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="inputNombre">Contacto 2:</label>
			<div class="controls">
			  <input type="text"  class='input-xxlarge' name='data[persona2]' id="persona2" value='<?php echo $data['persona2'];?>'>
			</div>
		</div>
		
		<div class="control-group">
			<label class="control-label" for="inputEmail">Email 2:</label>
			<div class="controls">
				<input type="email" class='input-xxlarge' name='data[email2]' id="inputEmail2" value='<?php echo $data['email2'];?>'>
			</div>
		</div>


		<div class="control-group">
			<label class="control-label" for="inputApellido">Tarifas:</label>
			<div class="controls">
			  <textarea rows='8' class='input-xxlarge' name='data[tarifas]'><?php echo $data['tarifas'];?></textarea>
			</div>
		</div>

		<div class="control-group">
			<label class="control-label" for="inputApellido">Notas:</label>
			<div class="controls">
			  <textarea rows='8' class='input-xxlarge' name='data[notas]'><?php echo $data['notas'];?></textarea>
			</div>
		</div>

		<input type='hidden' name='data[id]' value='<?php echo $id;?>' > 
		<input type='hidden' name='data[producto_id]' value='<?php echo $data['producto_id'];?>' > 
		<input type='hidden' name='accion' value='guardar' > 
		<input type='submit' class='btn btn-primary boton-guardar' value='Guardar Cambios'>
	</form>	
		
		
<style>
.control-label{
	float:left;
	width:150px;
	text-align:right;
	font-weight:bold;
}
</style>		